// pages/search/search.js
let app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        keywords: '',
        searchData: null
    },
    inputEnter() {
        let keywords = this.data.keywords
        let searchData = this.data.searchData
        if (keywords == '') {
            wx.showToast({
                title: '请输入商品名称',
                icon: 'error'
            })
        } else {
            wx.request({
                url: 'http://www.kangliuyong.com:10002/search',
                data: {
                    appkey: app.globalData.appkey,
                    name: keywords
                },
                success: (res) => {
                    console.log(res);
                    if (res.data.result.length > 0) {
                        this.setData({
                            searchData: res.data.result
                        })
                    } else {
                        wx.showToast({
                            title: '暂无搜索结果',
                            icon: 'error'
                        })
                    }
                }
            })
        }
    },
    delKeywords() {
        let keywords = this.data.keywords
        let searchData = this.data.searchData
        console.log(keywords);
        this.setData({
            keywords: '',
            searchData: null
        })
    }
})